package com.puris.dao.admin;

import com.puris.dao.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Sonata
 * @data 2021/11/26 20:26
 */
public class AllCompetitionDaoImpl implements AllCompetitionDao {
    @Override
    public StringBuffer selectCompetition(Connection connection) throws SQLException {
        PreparedStatement statement = null;
        ResultSet resultSet = null;

        StringBuffer competition = new StringBuffer();

        if (connection != null) {
            String sql = "select * from competition where id != ?";
            Object[] params = {"0"};

            resultSet = BaseDao.execute(connection, statement, resultSet, sql, params);

            competition.append("<table>");
            competition.append("<tr>");
            competition.append("<th>赛号</th>");
            competition.append("<th>名称</th>");
            competition.append("<th>日期</th>");
            competition.append("<th>工号</th>");
            competition.append("<th>教师</th>");
            competition.append("</tr>");

            while (resultSet.next()) {
                competition.append("<tr>");
                competition.append("<td>").append(resultSet.getString(1)).append("</td>");
                competition.append("<td>").append(resultSet.getString(2)).append("</td>");
                competition.append("<td>").append(resultSet.getString(3)).append("</td>");
                competition.append("<td>").append(resultSet.getString(5)).append("</td>");
                competition.append("<td>").append(resultSet.getString(6)).append("</td>");
                competition.append("</tr>");
            }

            competition.append("</table>");
        }
        BaseDao.closeResource(null, statement, resultSet);

        return competition;
    }
}
